package cn.iluwen.airline.DTOs;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * API基础响应对象
 * 所有API响应的基础格式
 */
@Data
@Schema(description = "API基础响应对象")
public class BaseResponse<T> {
    
    @Schema(description = "状态码：0=成功，非0=失败", example = "0")
    private Integer code;
    
    @Schema(description = "消息内容，成功时为'success'，失败时为错误信息", example = "success")
    private String message;
    
    @Schema(description = "响应数据，失败时为null")
    private T data;
    
    /**
     * 创建成功响应
     */
    public static <T> BaseResponse<T> success(T data) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode(0);
        response.setMessage("success");
        response.setData(data);
        return response;
    }
    
    /**
     * 创建无数据的成功响应
     */
    public static <T> BaseResponse<T> success() {
        return success(null);
    }
    
    /**
     * 创建失败响应
     */
    public static <T> BaseResponse<T> error(Integer code, String message) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
} 